package cn.com.chb.dakele.util;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.com.chb.dakele.domain.ReplayContent;

public class RePlay {
	private static final Log log = LogFactory.getLog(RePlay.class);

	public static void main(String args[]) throws IOException, InterruptedException {
		RePlay start = new RePlay();
		start.say();
	}
	public void say(){
		Dakele dakele = new Dakele();
		dakele.login("","");
		int a=0;
		for(int i=1;i<200;i++){
			String basurl="http://bbs.dakele.com/forum-43-"+i+".html";
			log.info(basurl);
			List<String> urls = dakele.getThreadURLs(basurl);
			for(String url:urls){
				ReplayContent content = dakele.preReplay(url);
				if(content!=null){
					//try {
						//String me = new String(messages.get(a).getBytes("GBK"), "UTF-8");
					//	content.setMessage(messages.get(a));
					//} catch (UnsupportedEncodingException e1) {
						//e1.printStackTrace();
					//}
					dakele.replay(content);
					log.info(content.getUrl());
					log.info(content.getMessage());
					try {
						Thread.sleep(16000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				a++;
				//if(a>messages.size()) a=0;
			}
		}
	}
}
